package com.changgou.order.controller;

import com.changgou.common.pojo.Result;
import com.changgou.common.pojo.StatusCode;
import com.changgou.order.config.TokenDecode;
import com.changgou.order.pojo.OrderItem;
import com.changgou.order.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName: CartController
 * @Auther: jeecg-boot
 * @Date: 2021/8/10 11:38
 * @Version 1.0
 */
@RestController
@RequestMapping("/cart")
public class CartController {
    @Autowired
    private CartService cartService;
    @Autowired
    private TokenDecode tokenDecode;

    @GetMapping("/add")
    public Result add(Integer num, Long id) {
        String username = tokenDecode.getUsername();
        cartService.add(num, id, username);
        return new Result(true, StatusCode.OK, "添加成功");
    }

    @GetMapping("/list")
    public Result<List<OrderItem>> list() {
        String username = tokenDecode.getUsername();
        List<OrderItem> list = cartService.list(username);
        return new Result<List<OrderItem>>(true,StatusCode.OK,"查询结果",list);

    }
}

